package com.yztc.love_travel.ui.fourtrip.presenter;

import com.yztc.love_travel.bean.fourtrip.FourTripBean;
import com.yztc.love_travel.bean.fourtrip.FourTripDetailsBean;
import com.yztc.love_travel.ui.fourtrip.model.FourTripModelImpl;
import com.yztc.love_travel.ui.fourtrip.model.IFourTripModel;
import com.yztc.love_travel.ui.fourtrip.view.IFourTripDetailsView;
import com.yztc.love_travel.ui.fourtrip.view.IFourTripView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 周旭 on 2016/11/28.
 */

public class FourTripPresenterImpl implements IFourTripPresenter {

    private IFourTripModel mRegionCultureModel;
    private IFourTripView mRegionCultureView;
    private IFourTripDetailsView mFourTripDetailsView;

    public FourTripPresenterImpl(IFourTripView mRegionCultureView, IFourTripDetailsView mFourTripDetailsView) {
        mRegionCultureModel = new FourTripModelImpl();
        this.mRegionCultureView = mRegionCultureView;
        this.mFourTripDetailsView = mFourTripDetailsView;
    }

    @Override
    public void getFourTripBean(String baseUrl, Map<String, Object> params) {
        mRegionCultureModel.getFourTripBean(baseUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FourTripBean>() {
                    @Override
                    public void onCompleted() {
                        mRegionCultureView.loadFinish();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mRegionCultureView.loadError();
                    }

                    @Override
                    public void onNext(FourTripBean fourTripBean) {
                        //显示获取成功的网络数据，
                       mRegionCultureView.showFourTripBeanData(fourTripBean);

                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mRegionCultureView.loadStart();
                    }
                });
    }

    @Override
    public void getFourTripDetails(String baseUrl, int destinationId) {
        mRegionCultureModel.getFourTripDetails(baseUrl,destinationId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FourTripDetailsBean>() {
                    @Override
                    public void onCompleted() {
                        mFourTripDetailsView.loadFinish();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mFourTripDetailsView.loadError();
                    }

                    @Override
                    public void onNext(FourTripDetailsBean fourTripDetailsBean) {
                        mFourTripDetailsView.showFourTripDetailsData(fourTripDetailsBean);
                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        mFourTripDetailsView.loadStart();
                    }
                });
    }
}
